<?php
namespace Common\Controller;
use Common\Controller\WeixinBaseBakController;
class MemberbaseController extends WeixinBaseBakController{

	function _initialize() {
		parent::_initialize();




//		$this->_check_login();




		$this->assign ( "imgUrl", C ( "SITE_URL" )."/Statics/Home/img/icon.png" );
		$this->assign ( "timeLineLink", U('Home/Index/index',array("j_id"=>$this->u["id"]),"",true) );
		$this->assign ( "tTitle", C ( "SITE_NAME" ) );
		$this->assign ( "tContent", C ( "SITE_DESCRIPTION" ) );

	}



	public function _check_login(){


		$s=$this->wx_u["subscribe"];


		if($s!=1){

			$this->error("请先关注公众号!",U("/Home/Index/auth"));

		}else{

			if(!$this->u){




				$data = array (
					"name" => rand_string(),
					'last_login_ip' => get_client_ip (),
					'create_time' => time (),
					'last_login_time' => time (),
					'status' => 1,
					'email_status' => 1,
					"model" => "Member",
					"pwd_hash" => rand_string (),
					"open_id"=>$this->wx_u[openid],
					"nickname"=>$this->wx_u[nickname],
					"avatar"=>$this->wx_u[headimgurl],
					"sex"=>$this->wx_u[sex],
					"bili"=>  $bili=C("FENXIAO_FENCHENGLV")
				);


				$guan_log=D("GuanLog")->where(array("open_id"=>$this->wx_u[openid]))->find();

				if($guan_log){

					$data["j_id"]=$guan_log["j_id"];

				}


				if(session("j_id")){

					$data["j_id"]=session("j_id");
				}

				D ( "Users" )->add ( $data );


				$userinfo = D("Users")->get_info_id(array("open_id"=>session("open_id")));



				$this->u=$userinfo;
				$this->u["avatar"]=$this->wx_u[headimgurl];
				session("uid",$userinfo["id"]);
				$this->assign("u",$this->u);




			}
			else{

				$this->u["avatar"]=$this->wx_u[headimgurl];


				$this->assign("u",$this->u);


			}



			if(!$this->u["tel"]&&ACTION_NAME!="bangding"){

				$this->error("请先绑定手机!",U('/User/Index/bangding'));
			}


		}






	}
//	public function get_wx_info(){
//
//
//
//
//
//	}
//
//	public function  get_c_auth(){
//
//
//
//
//
//
//
//
//
//
//
//
//	}
//
//
//	public function get_user_info()
//	{
//
//		$userinfo = D("Users")->get_info_id(array("id"=>1));
//
//
//
//		if($userinfo){
//			$this->u=$userinfo;
//
//			session("uid",$userinfo["id"]);
//			$this->assign("u",$this->u);
//		}
//
//
//
//
//
//
//	}
//
//
//	public function _get_auth()
//	{
//
//
//
//	}
}